<?php
/**************************************************************************
 *
 *   Copyright 2010 American Public Media Group
 *
 *   This file is part of AIR2.
 *
 *   AIR2 is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   AIR2 is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with AIR2.  If not, see <http://www.gnu.org/licenses/>.
 *
 *************************************************************************/

/**
 * SrcActivity
 *
 * Activity initiated by or on a Source.
 *
 * @property integer $sact_id
 * @property integer $sact_actm_id
 * @property integer $sact_src_id
 * @property integer $sact_prj_id
 * @property timestamp $sact_dtim
 * @property string $sact_desc
 * @property string $sact_notes
 * @property integer $sact_cre_user
 * @property integer $sact_upd_user
 * @property timestamp $sact_cre_dtim
 * @property timestamp $sact_upd_dtim
 * @property integer $sact_xid
 * @property string $sact_ref_type
 * @property Source $Source
 * @property ActivityMaster $ActivityMaster
 * @property Project $Project
 * @author rcavis
 * @package default
 */
class SrcActivity extends AIR2_Record {
    /* xid reference types */
    public static $REF_TYPE_RESPONSE = 'R';
    public static $REF_TYPE_TANK = 'T';


    /**
     * Set the table columns
     */
    public function setTableDefinition() {
        $this->setTableName('src_activity');
        $this->hasColumn('sact_id', 'integer', 4, array(
                'primary' => true,
                'autoincrement' => true,
            ));
        $this->hasColumn('sact_actm_id', 'integer', 4, array(

            ));
        $this->hasColumn('sact_src_id', 'integer', 4, array(

            ));
        $this->hasColumn('sact_prj_id', 'integer', 4, array(

            ));
        $this->hasColumn('sact_dtim', 'timestamp', null, array(

            ));
        $this->hasColumn('sact_desc', 'string', 255, array(

            ));
        $this->hasColumn('sact_notes', 'string', null, array(

            ));
        $this->hasColumn('sact_cre_user', 'integer', 4, array(
                'notnull' => true,
            ));
        $this->hasColumn('sact_upd_user', 'integer', 4, array(

            ));
        $this->hasColumn('sact_cre_dtim', 'timestamp', null, array(
                'notnull' => true,
            ));
        $this->hasColumn('sact_upd_dtim', 'timestamp', null, array(

            ));
        $this->hasColumn('sact_xid', 'integer', 4, array(

            ));
        $this->hasColumn('sact_ref_type', 'string', 1, array(
                'fixed' => true,
            ));

        $this->index('sact_ix_2', array(
                'fields' => array('sact_actm_id', 'sact_src_id', 'sact_prj_id', 'sact_dtim'),
                'type' => 'unique'
            )
        );
        $this->index('sact_ix_3', array(
                'fields' => array('sact_prj_id', 'sact_dtim'),
            )
        );

        // upd_dtim index for optimizing search index builds.
        $this->index('sact_ix_4', array(
                'fields' => array('sact_upd_dtim')
            )
        );

        // cre_user index looking at a user's activity
        $this->index('sact_ix_5', array(
                'fields' => array('sact_cre_user')
            )
        );

        parent::setTableDefinition();
    }



    /**
     * Set table relations
     */
    public function setUp() {
        parent::setUp();
        $this->hasOne('Source', array(
                'local' => 'sact_src_id',
                'foreign' => 'src_id',
                'onDelete' => 'CASCADE'
            ));
        $this->hasOne('ActivityMaster', array(
                'local' => 'sact_actm_id',
                'foreign' => 'actm_id',
                'onDelete' => 'CASCADE'
            ));
        $this->hasOne('Project', array(
                'local' => 'sact_prj_id',
                'foreign' => 'prj_id',
                'onDelete' => 'CASCADE'
            ));
    }


}
